﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Core.DMS;

namespace dms
{
    public partial class DocPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int docID = -1;

            if(Page.RouteData.Values["DocumentID"] != null)
                docID = int.Parse(Page.RouteData.Values["DocumentID"].ToString());
            else if(Request.QueryString["ID"] != null)
                docID = int.Parse(Request.QueryString["ID"]);

            if (docID != -1)
                OpenFile(Document.Get(docID));
            else
                throw new Exception("No document id was specified.");
        }

        void OpenFile(Document doc)
        {
            Response.Clear();
            Response.ContentType = doc.MimeType;
            Response.BufferOutput = false;
            doc.GetContent(Response.OutputStream);
        }
    }
}